package com.gongj.rabbit.direct;

import com.gongj.rabbit.utils.RabbitMQUtil;
import com.rabbitmq.client.BuiltinExchangeType;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;

import java.io.IOException;

/**
 * 路由模式
 */
public class Provider {

    public static void main(String[] args) throws IOException {
        //获取连接对象
        Connection conn = RabbitMQUtil.createConn();
        //获取通道对象
        Channel channel = conn.createChannel();
        /**
         * 参数1:交换机名称
         * 参数2:交换机类型
         */
        //绑定direct交换机(不存在就创建)
        channel.exchangeDeclare("logs_direct", BuiltinExchangeType.DIRECT);
        String key = "error";
        //发送消息
        channel.basicPublish("logs_direct",key,null,("指定的route key["+key+"]的消息，"+key+"级别的日志打印").getBytes());

        //关闭连接
        RabbitMQUtil.closeConn(channel,conn);
    }

}
